package com.meida.module.system.provider.service.impl;

import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.model.ListModel;
import com.meida.common.mybatis.model.PageModel;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.model.SaveModel;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.common.security.OpenHelper;
import com.meida.module.system.client.entity.SysBlacklist;
import com.meida.module.system.provider.mapper.SysBlacklistMapper;
import com.meida.module.system.provider.service.SysBlacklistService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 黑名单 实现类
 *
 * @author flyme
 * @date 2019-07-04
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysBlacklistServiceImpl extends BaseServiceImpl<SysBlacklistMapper, SysBlacklist> implements SysBlacklistService {

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody listEntityMap(ListModel model) {
        CriteriaQuery<EntityMap> cq = new CriteriaQuery(model, SysBlacklist.class);
        Long userId = OpenHelper.getUserId();
        cq.select(SysBlacklist.class, "blacklistId", "targetId");
        cq.eq(SysBlacklist.class, "ownerId", userId);
        return baseList(cq);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody pageList(PageModel model) {
        CriteriaQuery cq = new CriteriaQuery(model, SysBlacklist.class);
        Long userId = OpenHelper.getUserId();
        cq.select(SysBlacklist.class, "blacklistId", "targetId", "targetName", "createTime");
        cq.eq(SysBlacklist.class, "ownerId", userId);
        return basePageList(cq);
    }

    @Override
    public ResultBody add(SaveModel model) {
        CriteriaSave cs = new CriteriaSave(model, SysBlacklist.class);
        Long userId = OpenHelper.getUserId();
        cs.put("ownerId", userId);
        return baseAdd(cs);
    }
}
